<template>
  <div>
    <el-card shadow="never">
      <h3>申请成为管理员</h3>
    </el-card>
    <br>
    <el-card shadow="never">
      <el-form label-width="100px" size="mini">
        <el-form-item label="申请理由">
          <el-input v-model="addForm.reason" :rows="5" type="textarea" placeholder="请输入申请理由" />
        </el-form-item>
        <el-form-item label="">
          <el-button size="mini" type="primary" @click="addBtn">申请</el-button>
          <el-button style="margin-left:16px;" size="mini" @click="this.addForm = {}">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <br>
    <el-card shadow="never">
      <h3>申请历史</h3>
      <el-table
        :data="tableData"
        style="width: 100%"
        border
      >
        <el-table-column
          label="申请日期"
          align="center"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.createTime|formatDate2 }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="理由"
          align="center"
          width="300"
          show-overflow-tooltip=""
        >
          <template slot-scope="scope">
            <span>{{ scope.row.reason }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="申请结果"
          align="center"
        >
          <template slot-scope="scope">
            <el-tag v-if="scope.row.state === 0" type="warning">申请中</el-tag>
            <el-tag v-if="scope.row.state === 1" type="success">申请成功</el-tag>
            <el-tag v-if="scope.row.state === 2" type="danger">申请失败</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>

import * as applyApi from '@/api/apply'
import { getUser } from '@/utils/auth'
export default {
  name: '',

  data() {
    return {
      addForm: {},
      tableData: []
    }
  },
  created() {
    this.getData()
  },
  methods: {
    getData() {
      applyApi.list().then(res => {
        this.tableData = res.data.filter(item => item.userId === getUser().id)
      })
    },
    addBtn() {
      this.addForm.userId = getUser().id
      this.addForm.nickName = getUser().nickName
      applyApi.add(this.addForm).then(resp => {
        this.$notifySuccess('申请成功')
        this.getData()
        this.addForm = {}
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
